package cn.zhc.com.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by zhouhongchun on 2017/8/14
 */
public final class UtilsSP {
	public static String fileName = "zhc";
	private static SharedPreferences getSharedP(Context context) {
		return context.getApplicationContext().getSharedPreferences(fileName, Context.MODE_PRIVATE);
	}
	/**
	 * 缺省值为 false
	 * @param context
	 * @param key
	 * @return
	 */
	public static boolean getBoolean(Context context, String key) {
		return getSharedP(context).getBoolean(key, false);
	}

	public static void putBoolean(Context context, String key, boolean value) {
		SharedPreferences.Editor editor = getSharedP(context).edit();
		editor.putBoolean(key, value);
		editor.apply();
	}

	/**
	 * 缺省值为 ""
	 * @param context
	 * @param key
     * @return
     */
	public static String getString(Context context, String key) {
		return getSharedP(context).getString(key, "");
	}

	public static void putString(Context context, String key, String value) {
		SharedPreferences.Editor editor = getSharedP(context).edit();
		editor.putString(key, value);
		editor.apply();
	}

	/**
	 * 缺省值为-1
	 * @param context
	 * @param key
     * @return
     */
	public static int getInt(Context context, String key) {
		return getSharedP(context).getInt(key, -1);
	}

	public static void putInt(Context context, String key, int value) {
		SharedPreferences.Editor editor = getSharedP(context).edit();
		editor.putInt(key, value);
		editor.apply();
	}

}

